<template>
  <div>
    <el-row :gutter="10" style="margin-top: 20px;">
      <el-col :xs="24" :sm="24" :md="6" :lg="4">
        <div class="device-list addBox-line" @click="addComponent">
          <i class="el-icon-plus"></i>
          <span>add</span>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :md="4" :lg="4" v-for="(item, index) in componentList" :key="item.id">
        <div class="device-list">
          <div class="device-list-title" @click="addComponent(item)"><img src="@/assets/images/Icon.png" alt="">{{ item.componentName }}</div>
          <div class="device-list-num" @click="addComponent(item)">
            <p class="device-detail-title" v-if="item.isDisjunctor==1">ON</p>
            <div class="device-detail-swich" v-if="item.isDisjunctor==1">
              <el-switch
                v-model="value"
                active-color="#3a4cd5"
                inactive-color="#ff4949">
              </el-switch>
            </div>
            <el-progress type="dashboard" :percentage="percentage" :color="colors" :width="widthPercentage" v-else></el-progress>
            <p class="device-detail-samllTitle">4mouths a go</p>
          </div>
          <div class="device-list-footer">
            <span class="el-icon-edit" @click="addComponent(item)"></span>
            <span class="el-icon-delete" @click="handleDelete(item,index)"></span>
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  props:['componentList'],
  name: "tabSetting",
  data(){
    return{
      value: true,
      percentage: 10,
      colors: [
        {color: '#f56c6c', percentage: 20},
        {color: '#e6a23c', percentage: 40},
        {color: '#5cb87a', percentage: 60},
        {color: '#1989fa', percentage: 80},
        {color: '#6f7ad3', percentage: 100}
      ],
      widthPercentage: 70
    }
  },
  methods:{
    addComponent(row){
      this.$emit('addComponent', row)
    },
    handleDelete(item, index){
      let that = this
      this.$confirm(`确认delete【${item.componentName}】该元器件, 是否继续?`, '提示', {
        confirmButtonText: 'confirm',
        cancelButtonText: 'cancel',
        type: 'warning'
      }).then(() => {
        that.$emit('componentDelete', index)
      }).catch(() => {
      });
    }
  }
}
</script>

<style scoped>
.device-list {
  box-shadow: 0 2px 2px #ddd;
  border: 1px solid #ddd;
  border-radius: 5px;
  box-sizing: border-box;
  margin-bottom: 10px;
  background: #fff;
}

.device-list-title {
  display: flex;
  align-items: center;
  padding: 20px 0 10px 30px;
}

.device-list-num {
  height: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.device-detail-title {
color: rgb(0, 84, 254);
  margin: 10px 0;
}

.device-detail-samllTitle {
  color: rgb(116, 121, 140);
  font-size: 14px;
  margin:  0;
}

.addBox-line {
  height: 208px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.addBox-line i {
  font-size: 20px;
  height: 45px;
  width: 45px;
  text-align: center;
  line-height: 45px;
  margin-bottom: 13px;
  background: #eee;
  font-weight: bold;
  border-radius: 50%;
}
</style>
